import { getOrderTrade, getUserAddressList } from "api/api"
export default {
    state: {
        trade: {},
        address: []
    },
    getters: {
        defaultIndex(state) {
            return state.address.findIndex(item => item.isDefault === `1`)
        }
    },
    mutations: {
        getTrade(state, trade) {
            state.trade = trade
        },
        getAddress(state, address) {
            state.address = address
        }
    },
    actions: {
        //获取订单的交易信息
        async getTrade({ commit }) {
            try {
                const { code: tradeCode, data: trade } = await getOrderTrade();
                const { code: addressCode, data: address } = await getUserAddressList();
                if (tradeCode === 200 && addressCode === 200) {
                    commit("getTrade", trade);
                    commit("getAddress", address);
                }
            } catch (e) {
                return Promise.reject(e)
            }
        },
    }
}
